package com.jt.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.User;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.jt.service.UserService;
import redis.clients.jedis.JedisCluster;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	@Autowired
	private JedisCluster jedisCluster;
	@RequestMapping("/findUserAll")
	public List<User> findAll(){
		return userService.findAll();
	}

	/*
	* http://sso.jt.com/user/check/*/
	@RequestMapping("/check/{param}/{type}")
	public JSONPObject checkUser(@PathVariable String param,@PathVariable Integer type,String callback){
		boolean flag=userService.checkUser(param,type);
		SysResult sysResult=SysResult.success(flag);
		return new JSONPObject(callback, sysResult);
	}
	@RequestMapping("findUserList")
	@ResponseBody
	public List<User> findUserList(){
		return userService.findAll();
	}

	@RequestMapping("/query/{ticket}")
	public JSONPObject findUserByTicket(@PathVariable String ticket,String callback){
		String json=jedisCluster.get(ticket);
		if (StringUtils.hasLength(json)){
			return new JSONPObject(callback, SysResult.success(json));
		}else {
			return new JSONPObject(callback, SysResult.fail());
		}
	}
	
	
	
}
